package cn.yusei.teamTribe.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

@Controller
public class CommonInterceptor extends HandlerInterceptorAdapter{

	@Value("${encoding}")
	private String encoding;
	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
	{
		try
		{
			request.setCharacterEncoding(encoding);
			response.setCharacterEncoding(encoding);
			response.setHeader("Access-Control-Allow-Origin","*");   
		    response.setHeader("Access-Control-Allow-Methods","GET,POST");
		}
		catch (Exception e)
		{
			e.printStackTrace();
			return false;
		}
		return true;
	}
	
}
